package com.ruoyi.stock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.stock.domain.StockConfig;
import com.ruoyi.stock.service.IStockConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 基本配置Controller
 * 
 * @author ruoyi
 * @date 2025-01-07
 */
@RestController
@RequestMapping("/stock/stockconfig")
public class StockConfigController extends BaseController
{
    @Autowired
    private IStockConfigService stockConfigService;

    /**
     * 查询基本配置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(StockConfig stockConfig)
    {
        startPage();
        List<StockConfig> list = stockConfigService.selectStockConfigList(stockConfig);
        return getDataTable(list);
    }

    /**
     * 导出基本配置列表
     */
    @Log(title = "基本配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockConfig stockConfig)
    {
        List<StockConfig> list = stockConfigService.selectStockConfigList(stockConfig);
        ExcelUtil<StockConfig> util = new ExcelUtil<StockConfig>(StockConfig.class);
        util.exportExcel(response, list, "基本配置数据");
    }

    /**
     * 获取基本配置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stockConfigService.selectStockConfigById(id));
    }

    /**
     * 新增基本配置
     */
    @Log(title = "基本配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockConfig stockConfig)
    {
        return toAjax(stockConfigService.insertStockConfig(stockConfig));
    }

    /**
     * 修改基本配置
     */
    @Log(title = "基本配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockConfig stockConfig)
    {
        return toAjax(stockConfigService.updateStockConfig(stockConfig));
    }

    /**
     * 删除基本配置
     */
    @Log(title = "基本配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stockConfigService.deleteStockConfigByIds(ids));
    }
}
